//
//  DeviceDelegateHelper.m
//  ECSDKDemo_OC
//
//  Created by jiazy on 14/12/5.
//  Copyright (c) 2014年 ronglian. All rights reserved.
//

#import "DeviceDelegateHelper.h"
#import "UIImageView+WebCache.h"
#import "ECMultiDeviceState.h"

NSString *const CellMessageReadCount = @"CellMessageReadCount";
NSString *const CellMessageUnReadCount = @"CellMessageUnReadCount";

@interface DeviceDelegateHelper()
@property(atomic, assign) NSUInteger offlineCount;
@end

@implementation DeviceDelegateHelper{
 }
//第一步：创建单例方法

+(DeviceDelegateHelper*)sharedInstance

{
    
    static DeviceDelegateHelper *devicedelegatehelper;
    
    static dispatch_once_t devicedelegatehelperonce;
    
    dispatch_once(&devicedelegatehelperonce, ^{
        
        devicedelegatehelper = [[DeviceDelegateHelper alloc] init];
        
    });
    
    return devicedelegatehelper;
    
}

//第二步：连接云通讯的服务平台，实现ECDelegateBase代理的方法

/**
 
 @brief 连接状态接口
 
 @discussion 监听与服务器的连接状态 V5.0版本接口
 
 @param state 连接的状态
 
 @param error 错误原因值
 
 */

-(void)onConnectState:(ECConnectState)state failed:(ECError*)error {
    
    switch (state) {
            
        case State_ConnectSuccess://连接成功
            
            [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onConnected object:[ECError errorWithCode:ECErrorType_NoError]];
            
            break;
            
        case State_Connecting://正在连接
            
            [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onConnected object:[ECError errorWithCode:ECErrorType_Connecting]];
            
            break;
            
        case State_ConnectFailed://失败
            
            [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onConnected object:error];
            
            break;
            
        default:
            
            break;
            
    }
    
}
/**
 @brief 网络改变后调用的代理方法
 @param status 网络状态值
 */
- (void)onReachbilityChanged:(ECNetworkType)status{
     [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_onNetworkChanged object:@(status)];
}

@end
